<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>生产审核页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/res/js/util.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<!--当前状态 根据状态定职位-->
<input type="hidden" name="status" id="status">
<table class="layui-hide" id="test" lay-filter="test"></table>


<script type="text/html" id="barDemo">
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="watch">查看详情</button>
    <a class="layui-btn layui-btn-xs" lay-event="HqReview">查询审核详情</a>
</script>


<script type="text/html" id="barDemo2">
    {{# if(returnUser()){ }}
        {{# if(authorization("audit:managerAudit")){ }}
            {{# if(d.state<60){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('60')" lay-event="audit" >审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else if(authorization("audit:sellAudit")){ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# } }}
    {{# }else{ }}
        <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
    {{# } }}
</script>

<script type="text/html" id="img">
    <img src="../user/getPicture.action?userId={{d.id}}" width="50" height="50" onclick="showBig(this)"/>
</script>

<script src="/res/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    var openIndex = null;
    var table = null;
    var array = new Array();
    var ids = [];
    layui.use(['table', 'layer'], function () {
        table = layui.table;

        table.render({
            elem: '#test'
            , url: '/hqPlan/findAll'
            // , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '用户数据表'
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,height:600
            ,totalRow: true  //开启合计
            , cols: [[
                {field: 'planName',fixed: 'left', title: '计划名称', width: 120,align:"center",unresize: true, totalRowText: '合计'}
                , {field: 'planPrice', title: '计划金额', width: 120,align:"center", totalRow: true}
                , {field: 'planKtime', title: '开始日期', width: 150,align:"center"}
                , {field: 'planJtime', title: '结束日期', width: 150,align:"center"}
                , {field: 'oper', title: '操作人', width: 100,align:"center"}
                , {field: 'optime', title: '发布时间', width: 150,align:"center"}
                , {field: 'state', title: '状态',unresize : true,templet:function(d){
                        if(d.state==20){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">待审核</p>';
                        }else if(d.state==60){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过,完成审核</p>';
                        }else if(d.state==61){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>';
                        }else if(d.state==70){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">制造中</p>';
                        }else if(d.state==71){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">制造完成</p>';
                        }else if(d.state==80){
                            return '<p class="layui-btn layui-btn-normal layui-btn-xs">质检中</p>';
                        }else if(d.state==81){
                            return '<p class="layui-btn layui-btn-normal layui-btn-xs">已入库</p>';
                        }
                    },align:"center"}
                , {fixed: 'right', title: '查询信息', toolbar: '#barDemo', width: 260,align:"center"}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo2', width: 100,align:"center"}
            ]]
            , page: true
            , where:{   //生产过滤状态为0,10
                auditStatus : '0,10'
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
                case 'query':
                    table.reload('test', {
                        where: {
                            userName: $("#name").val()
                        },

                        page: {
                            curr: 1
                        }
                    })
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if(obj.event === 'watch'){
                var id = data.planId;
                openIndex = layer.open({
                    type: 2,
                    maxmin: true,
                    area: ['50%', '65%'], //宽高
                    content: `/ok-admin/pages/hqPlan/pdetail.html?id=${id}`,
                    success:function (layero,index) {
                        var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
                        var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
                        body.find("#planId").val(id);
                    }
                })
            }else if(obj.event === "audit"){
                var id = data.planId;
                //获取所点击审核的人的权限
                let status = $("#status").val();
                console.info($("#status").val());
                openIndex = layui.layer.open({
                    type: 2,
                    area: ['55%', '60%'], //宽高
                    title: '审核信息',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    // content:  $("#popUpdateTest"),
                    content:`/ok-admin/pages/audit/auditForm.html?id=${id}&status=${status}&audit=production`
                });
            }else if(obj.event === "HqReview"){
                var id = data.planId;
                openIndex = layer.open({
                    type: 2,
                    area: ['85%', '85%'], //宽高
                    title: '审核记录',
                    skin: 'layui-layer-molv',//样式
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    shift:1,//弹出框动画效果
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }
        });
        //审核请求
        window.openAudit = function (status) {
            $("#status").val(status);
        }
    });

    /**
     * 关闭层
     */
    function closeOpen(msg) {
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg, {time: 1000,icon:1}, function () {
            table.reload("test");//刷新表格
        })
    }

    /**
     * 错误提示 关闭弹出层
     */
    function errorCloseOpen(msg){
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg,{time:2000,icon:2},function(){
            table.reload("test");
            //window.location.reload(true);
        });
    }
    function submitAudit(obd) {
        var url = "../../../hqPlan/submitAudit"
        $.post(url,{jsonStr:JSON.stringify(obd)},function (obj) {
            if(obj.status==20){
                layer.msg(obj.message,{time: 1000}, function () {
                    array = "";
                    table.reload("test");//刷新表格
                })
            }else {
                layer.msg('请先进行药品操作', {icon: 5, time: 2000});
            }
        },'json')
    }

    /**
     * 图片
     */
    function showBig(obj) {
        $("#imgDiv").fadeToggle(1000);
        $("#imgDiv_img").prop("src", obj.src)
    }
</script>
<div id="imgDiv" style="display:none;position:absolute;left:20%;top:10%">
    <img src="" id="imgDiv_img" width="100%" height="100%" onclick="showBig(this)">
</div>
</body>
</html>